<template>

	<view class="news">
		<div class="title">
			<div class="left">资讯</div>
			<div class="more">更多</div>
		</div>
		<div @click="toDetail(item.id)" class="list" v-for="item in list" :key="item.id">
			<div class="left">
				<div class="tit">
					{{item.title}}
				</div>
				<div class="date">
					{{formatDate(item.addtime)}}
				</div>

			</div>
			<image class="img" :src="imgUl+item.picture"></image>
		</div>

	 
	</view>
</template>

<script>
	import {getNewsList} from '../../service/news.js'
	import {BASE_IMG_URL} from '../../utils/config.js'
	import  dayjs from 'dayjs'
	export default {
		data() {
			return {
				list: [],
				imgUl:BASE_IMG_URL,
				params: {
					key: "",
					type: 1,
					page: 1,
					psize: 25
				}
			}
		},
		mounted() {
			this.getNewsData();
			
		 
		},
		
		methods: {
			toDetail(id){
				uni.navigateTo({
					url:`/pages/news/detail?id=${id}`
				})
				
				// uni.redirectTo({
				// 	url:`/pages/news/detail?id=${id}`
				// })
			 
			},
			formatDate(val){
				
			 return	dayjs(val).format('YYYY-MM-DD')
				
			},

			async getNewsData() {

				const {
					data,
					errCode
				} = await getNewsList(this.params);

				if (errCode === 10000) {
					this.list = data.list;
					
					console.log(this.list)
				}

			},

		}
	}
</script>

<style scoped lang="less">
	.news {
		display: flex;

		flex-direction: column;
		margin: 0 34rpx;
		box-sizing: border-box;

		.title {
			display: flex;
			justify-content: space-between;
			align-items: center;

			.left {
				font-size: 36rpx;
			}

		}

		.list {
			display: flex;
			margin-top: 50rpx;

			.left {
				flex: 1;

				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.tit {

					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
					overflow: hidden;
					text-overflow: ellipsis;
					font-size: 32rpx;
					line-height: 48rpx;

				}

				.date {
					color: #5f5f5f;
				}
			}

			.img {
				width: 240rpx;
				height: 160rpx;
				margin-left: 64rpx;
				border-radius: 15rpx;

			}
		}

	}
</style>